<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace AlibabaCloud\Client\Request\Traits;

trait AcsTrait
{
    public $version;
    public $product;
    public $action;
    public $serviceCode = "";
    public $endpointType = "openAPI";
    public $network = "public";
    public $endpointMap;
    public $endpointRegional;
    public $endpointSuffix = "";
    public function action($action)
    {
        $this->action = \AlibabaCloud\Client\Filter\ApiFilter::action($action);
        return $this;
    }
    public function endpointSuffix($endpointSuffix)
    {
        $this->endpointSuffix = \AlibabaCloud\Client\Filter\ApiFilter::endpointSuffix($endpointSuffix);
        return $this;
    }
    public function network($network)
    {
        $this->network = \AlibabaCloud\Client\Filter\ApiFilter::network($network);
        return $this;
    }
    public function version($version)
    {
        $this->version = \AlibabaCloud\Client\Filter\ApiFilter::version($version);
        return $this;
    }
    public function product($product)
    {
        $this->product = \AlibabaCloud\Client\Filter\ApiFilter::product($product);
        return $this;
    }
    public function endpointType($endpointType)
    {
        $this->endpointType = \AlibabaCloud\Client\Filter\ApiFilter::endpointType($endpointType);
        return $this;
    }
    public function serviceCode($serviceCode)
    {
        $this->serviceCode = \AlibabaCloud\Client\Filter\ApiFilter::serviceCode($serviceCode);
        return $this;
    }
    public function resolveHost()
    {
        if($this->uri->getHost() !== "localhost") {
            return NULL;
        }
        $region_id = $this->realRegionId();
        $host = "";
        $this->resolveHostWays($host, $region_id);
        if(!$host) {
            throw new \AlibabaCloud\Client\Exception\ClientException("No host found for " . $this->product . " in the " . $region_id . ", you can specify host by host() method. " . "Like \$request->host('xxx.xxx.aliyuncs.com')", \AlibabaCloud\Client\SDK::HOST_NOT_FOUND);
        }
        $this->uri = $this->uri->withHost($host);
    }
    private function resolveHostWays(&$host, $region_id)
    {
        if($this->network === "public" && isset($this->endpointMap[$region_id])) {
            $host = $this->endpointMap[$region_id];
        }
        if(!$host && $this->endpointRegional !== NULL) {
            $host = \AlibabaCloud\Client\AlibabaCloud::resolveHostByRule($this);
        }
        if(!$host) {
            $host = \AlibabaCloud\Client\AlibabaCloud::resolveHost($this->product, $region_id);
        }
        if(!$host && $this->serviceCode) {
            $host = \AlibabaCloud\Client\Regions\LocationService::resolveHost($this);
        }
    }
    public function realRegionId()
    {
        if($this->regionId !== NULL) {
            return $this->regionId;
        }
        if($this->httpClient()->regionId !== NULL) {
            return $this->httpClient()->regionId;
        }
        if(\AlibabaCloud\Client\AlibabaCloud::getDefaultRegionId() !== NULL) {
            return \AlibabaCloud\Client\AlibabaCloud::getDefaultRegionId();
        }
        throw new \AlibabaCloud\Client\Exception\ClientException("Missing required 'RegionId' for Request", \AlibabaCloud\Client\SDK::INVALID_REGION_ID);
    }
}

?>